<?php

class Site_Exception extends CMS_Exception {}

class Site_Invalid_Exception extends Site_Exception {}

class Site {

	private static $instance;

	private $id;
	private $name;
	private $output;
	
	public function getID(){
		return $this->id;
	}

	public function getOutput(){
		$config = Config::getInstance();
		if(isset($config['output'])){
			return $config['output'];
		}
		return $this->output;
	}

	public function getValue($k){
		$config = Config::getInstance();
		if(isset($config[$k])){
			return $config[$k];
		}
		return $this->$k;
	}

	private static function loadInstance(){
		$config = Config::getInstance();
		if(!isset($config['site'])){
			throw new Site_Invalid_Exception("Site configuration unavailable");
		}
		$result = Database::getInstance()->query("SELECT * from `sites` WHERE `id` = %u", $config['site']);
		Site::$instance =$result->fetch_object('Site');
		if(!isset(Site::$instance)){
			throw new Site_Invalid_Exception("Site configuration could not be loaded");
		}
	}

	public static function getInstance(){
		if(!isset(Site::$instance)){
			throw new Site_Invalid_Exception("Site is undefined");
		}
		return Site::$instance;
	}

	public static function Load(){
		
		Site::loadInstance();

	}


}
